// components/findTeam/teamInvite/teamInvite.js
import api from '../../../api/index'
import store from '../../../store/index'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    mate:Object,
    teamID:String,
    currNum:Number,
    needNum:Number,
    skill:Array
   
    

  },

  /**
   * 组件的初始数据
   */
  data: {
    is_my:false,
  },

  /**
   * 组件的方法列表
   */
  attached(){
    var openid = this.data.mate.openid
    var params = {openid}
    this.status()  //获取是否是自己能够同意的状态
    api.userInfo.getSkill(params).then(res=>{
      console.log(res)
      this.setData({
        ['mate.skill']:res
      })
    })
  },
  methods: {
    status:function(){
      var myOpenid = store.data.openid
      var thisOpenid = this.data.mate.openid
      if(myOpenid==thisOpenid){
        this.setData({
          is_my:true
        })
      }
    },
    AC:function(){
      var openid = this.data.mate.openid
      var teamID = this.data.teamID
      var need = this.data.needNum
      var curr = this.data.currNum
      var inc = 1
      console.log(need)
      console.log(curr)
      if(need==curr){
        wx.showToast({
          title: '队伍人数已满',
          icon:"error"
        })
        return 0;
      }
      var status = "AC"
      var params=  {openid,teamID,status,inc}
      api.team.accept(params).then(res=>{
        wx.showToast({
          title: '已加入',
        })
        this.triggerEvent("name",{})
        console.log(res)
      })
    },
    WA:function(){
      var openid = this.data.mate.openid
      var teamID = this.data.teamID
      var status = "WA"
      var inc = -1;
      var params=  {openid,teamID,status,inc}
      api.team.accept(params).then(res=>{
        wx.showToast({
          title: '已拒绝',
        })
        this.triggerEvent("name",{})
      })
    },
    toLookMe: function() {  //查看队长信息，跳转到查看页面
      var openid = this.data.mate.openid
      console.log(openid)
      wx.navigateTo({
        url: '/pages/lookMe/lookMe?openid=' + openid,
      })
    },
  }
})
